<?php 

	class Mysql {
		
		protected $host;
		protected $user;
		protected $pwd;
		protected $dbname;
		
		protected $conn = NULL;
		
		public function __construct(){
			
			$this->host = 'localhost';
			$this->user = 'root';
			$this->pwd = '';
			$this->dbname = 'test';
			
			$this->connect($this->host, $this->user, $this->pwd, $this->dbname);
			
			//echo '<pre >';
			//var_dump($this->conn);
			
			//$this->query('INSERT INTO img1 (filename,filepath,pubtime) values ("hahha","hahaha",1234124)');
			
			if($this->conn === NULL) {
				echo 'connect failed:' . Mysqli_connect_error() . '<br />';
				echo 'please check the config file.';
				exit();
			}
			
			echo '<meta charset = "utf8">';
			
		}
		
		protected function add($filename, $filepath, $pubtime) {
			$sql = 'INSERT INTO img1 (filename, filepath, pubtime) values (" ' . $filename . ' ", "' . $filepath . ' ", ' .$pubtime .')';
			/*
			$sql = 'INSERT INTO img1 (filename,filepath, pubtime) values ("';
			$sql .= $filename . '","';
			$sql .= $filepath . '",';
			$sql .= $pubtime . ',)';
			*/
			//$sql = 'INSERT INTO img1 (filename,filepath, pubtime) values ("wacawoca","lisilisi",11110000)';
			
			if($this->query($sql)){
				echo '添入数据库成功. <br />';
			}else{
				echo '添入数据库失败. <br />';
				echo mysqli_error($this->conn) . '<br />';
			}
		}
		
		private function connect($h, $u, $p, $d) {
			$this->conn = mysqli_connect($h, $u, $p, $d);
			return $this->conn;
		}
		
		private function query($sql) {
			return mysqli_query($this->conn, $sql);
		}
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	